<script type="text/javascript" src="<?=base_url()?>js/popup.js"></script>
<link href="<?=base_url()?>css/popup.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
$j(document).ready(function(){
				
	//CLOSING POPUP	
	//Click out event!
	$j("#background-popup").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$j(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

}); 
function reloadpage() {
	var sort_type = $j('#sort-type').val();
	var per_page = $j('#per-page').val();
	window.location = '<?=base_url()?>store/reloadpage/<?=$this->uri->segment(3);?>/' + sort_type + '/' + per_page;
}
function reloadcategory()
{
	var sortcategory = $j('#sortcategory').val();
	window.location = '<?=base_url()?>store/category/' + sortcategory;
}
function addtocart(id) 
{
	$j.ajax({
		url: '<?=base_url()?>store/addtocart/',
		type: 'POST',
		data: "product_id=" + id,
		dataType: "html",
		success: function(html) {
			updatecart();
			$j('#content-pop').html(html);
			centerPopup();
	        loadPopup();
		}
	})
}
</script>

<div id="popup-box">
	
    <div id="popup-shopping">
    	<div class="close"><a href="javascript:disablePopup()"><img src="<?=base_url()?>img/CloseButton-Up.png" alt="Close" /></a></div>
        <div style="clear:both"></div>
        <div style="clear:both;padding-top:54px">
           <div id="content-pop" style="width:400px;margin:0 auto"></div>
        </div>
        <br/>
    </div>
</div>
<div id="background-popup"></div>
        <div id="store" style="margin-bottom:14px;">
            <div class="cat" style="background:#E8E8E8;border:none;margin:0;padding:0;width:763px;float:right;padding-left:10px;padding-right:10px;position:relative;font-family:Trebuchet MS, Arial, Helvetica, sans-serif;">
                <div style="float:left;line-height:3.8em;">
                  <span class="grey">Products Available:</span>
                  <span class="green"><?=$total?><?php if($links) print "&nbsp;&nbsp;Page ".$links; ?></span>
                </div>
              
                <div style="float:right;width:322px">
               <table cellpadding="0" cellspacing="0" border="0">
                <tr>
                  <td><div class="options" style="text-align:left;">
                  <span class="green">SORT</span><br />
                    <!--
                	<select id="sort-type" onchange="reloadpage()" style="width:120px;">
                    	<option value="0">Sort products</option>
                    	<option value="1"<?php if($this->session->userdata('sort_type') == 1) print ' selected="selected"'; ?>>Price - Low to High</option>
                        <option value="2"<?php if($this->session->userdata('sort_type') == 2) print ' selected="selected"'; ?>>Price - High to Low</option>
                        <option value="0"<?php if($this->session->userdata('sort_type') == 0) print ' selected="selected"'; ?>>Alphabetic</option>
                    </select>-->
                    <select style="width:120px;" onchange="reloadcategory()" id="sortcategory">
                      <? foreach($categories as $c)
					  {
						  $selected = '';
						  if($current_page == $c['id'])
						  {
							  $selected = 'selected="selected"';
						  }
						  ?>
                          <option value="<?=$c['id']?>" <?=$selected?>><?=$c['title']?></option>
                       <?
					  }
					  ?>
                    </select>
                </div>
                </td>
                <td>
                <div class="options" style="text-align:left;width:140px;">
                  <span class="green">DISPLAY</span><br />
                	<select id="per-page" onchange="reloadpage()">
                    	<option value="9"<?php if($this->session->userdata('per_page') == 9) print ' selected="selected"'; ?>>Show 9 products per page</option>
                        <option value="18"<?php if($this->session->userdata('per_page') == 18) print ' selected="selected"'; ?>>Show 18 products per page</option>
                        <option value="36"<?php if($this->session->userdata('per_page') == 36) print ' selected="selected"'; ?>>Show 36 products per page</option>
                    </select>                    
                </div>
                </td>
               </tr>
               </table>
               </div>
            </div>
            <div style="clear:both;"></div>
          
            <?php if(count($products) > 0) { $valid=0; ?>
            <?php foreach($products as $product) {
            	if($product['multiplesize']==1){
            		$multiple_stock = json_decode($product['size'],true);
					$stock_all= $multiple_stock['XXXS']+$multiple_stock['XS']+$multiple_stock['M']+$multiple_stock['XL']+$multiple_stock['3XL']+$multiple_stock['5XL']+$multiple_stock['6'];
					$stock_all=$stock_all+$multiple_stock['10']+$multiple_stock['14']+$multiple_stock['18']+$multiple_stock['22']+$multiple_stock['XXS']+$multiple_stock['S']+$multiple_stock['L'];
					$stock_all=$stock_all+$multiple_stock['XXL']+$multiple_stock['4XL']+$multiple_stock['6XL']+$multiple_stock['8']+$multiple_stock['12']+$multiple_stock['16']+$multiple_stock['20'];
					if($stock_all > 0){$valid=1;}else{$valid=0;}
            	}else{
            		if ($product['stock'] > 0){$valid=1;}else{$valid=0;}
            	}
            			
            		 
            	if ($valid==1) 
            	{
				$photo = $this->Product_model->thumb_photo($product['id']); ?>
            <div class="product-thumb" style="float:left;">
            	<?php if($photo) { ?>
            	<a href="<?=base_url()?>store/product/<?=$product['id']?>"><img src="<?=base_url()?>uploads/products/<?=md5('mbb'.$product['id'])?>/thumb2/<?=$photo['name']?>" /></a>
                <?php } else { ?>
                <a href="<?=base_url()?>store/product/<?=$product['id']?>"><img height="221" src="<?=base_url()?>img/nophoto.jpg" /></a>
                <?php } ?>
                <div class="product-box">
                <p class="p-name"><?=$product['title']?></p>
                <p class="p-price">
                	<?php 
                	if($product['sale_price'] < $product['price']) { 
						$price = money_format('%i',$product['price']);
						$sale_price = money_format('%i',$product['sale_price']); ?>
                	<span class="old">$<?=$price?></span> $<?=$sale_price?>
                    <?php } else { 
						$price = money_format('%i',$product['price']); ?>
                    <span class="normal">$<?=$price?></span>
                    <?php } ?>
                </p>
                <div style="margin-top:2px">
                   <table cellpadding="0" cellspacing="0" border="0" width="100%">
                     <tr>
                       <td align="center"><a href="<?=base_url()?>store/product/<?=$product['id']?>"><img src="<?=base_url()?>img/view-product-button.png" alt="View Product" /></a></td>
<!--                       <td width="29">&nbsp;</td>-->
<!--                       <td><a href="javascript:addtocart(<?=$product['id']?>)"><img src="<?=base_url()?>img/add-to-basket-button.png" alt="Add To Basket" /></a></td>-->
                     </tr>
                   </table>
                 </div>
                </div>
            </div>
            <?php }
					} ?>
            <?php } else { ?>
            <div class="notfound">
            	<h2>Sorry your search returned no results.</h2>
                <p>Try searching for a brand name, product name, colour or item description such as cotton shirt</p>
            </div>
			<?php } ?>
            <dl></dl>
        </div>